package com.kaiyiweitong.tongxing.other;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Administrator on 2017/12/5 0005.
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    int mSpace;
    int mType;

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        switch (mType) {
            case 0:
                outRect.top = mSpace;
                outRect.bottom = mSpace;
                outRect.left = mSpace;
                outRect.right = mSpace;
                break;
            case 1:
                if (parent.getChildAdapterPosition(view) != 0) {
                    outRect.top = mSpace;
                }
                break;
            case 2:
                if (parent.getChildAdapterPosition(view) == 0) {
                    outRect.left = mSpace;
                }
                outRect.right = mSpace;
                break;
        }
    }

    /**
     * 设置RecyclerView条目间距
     *
     * @param space 间距大小  px
     * @param type  0 全部间距     1 上下间距     2 左右间距
     */
    public SpaceItemDecoration(int space, int type) {
        this.mSpace = space;
        this.mType = type;
    }
}
